<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/04/05 19:58:31 $)
// $RCSfile: impex.emailqueues.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Return the Total Pages for this Plugin
*/
function getPluginTotalPages6()
{
	return 1;
}

/**
* Run the specific page for plugin
*/
function runPluginPage6($page)
{
	global $impexDB, $_IMPEXHASH;

	$queuelist = $queueaddresslist = array();
	$impexDB->query("SELECT * FROM `queue` ORDER BY `queue_id` ASC;");
	while ($impexDB->nextRecord())
	{
		$queuelist[$impexDB->Record["queue_id"]] = $impexDB->Record;
	}

	$impexDB->query("SELECT * FROM `queue_addresses` ORDER BY `queue_addresses_id` ASC;");
	while ($impexDB->nextRecord())
	{
		$queueaddresslist[$impexDB->Record["queue_id"]][] = $impexDB->Record;
	}

	foreach ($queuelist as $key=>$val)
	{
		$newdepartmentid = intval($_IMPEXHASH["departmentpointer"][$key]);
		if (empty($newdepartmentid))
		{
			displayStatus("<font color='red'>WARNING:</font> Import of Email Queue Failed due to Non Existant Department: ".htmlspecialchars($val["queue_name"]));
		} else {
			if (!_is_array($queueaddresslist[$key]))
			{
				continue;
			}
			foreach ($queueaddresslist[$key] as $qemailkey=>$qemailval)
			{
				$_emailqueueid = _impexInsertEmailQueue($qemailval["queue_address"]."@".$qemailval["queue_domain"], $newdepartmentid, "pipe", "", "", "", "", "");

				$_IMPEXHASH["queuepointer"][$key] = $_emailqueueid;

				displayStatus("Imported Email Queue: ".htmlspecialchars($qemailval["queue_address"]."@".$qemailval["queue_domain"]));
			}
		}
	}

	return true;
}
?>